package com.fit.pages.homeworkRecords;


import java.util.List;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AdminAccess;
import com.fit.annotations.AnonymousAccess;
import com.fit.annotations.ProfessorAccess;
import com.fit.annotations.StudentAccess;
import com.fit.dao.course.CourseDAO;
import com.fit.dao.homework.HomeworkDAO;
import com.fit.dao.language.LanguageDAO;
import com.fit.dao.student.StudentDAO;
import com.fit.dao.user.UserDAO;
import com.fit.entities.course.Course;
import com.fit.entities.homework.Homework;
import com.fit.entities.language.Language;
import com.fit.entities.student.Student;
import com.fit.entities.user.User;
import com.fit.pages.ErrorPage;

@AdminAccess
@AnonymousAccess
@ProfessorAccess
@StudentAccess
public class View {

	@Property
	@Persist
	private Course course;
	@Inject
	private CourseDAO courseDAO;
	@InjectPage
	private ErrorPage errorPage;

	@Property
	private List<Course> courses;
	
	void onActivate() {
		courses = courseDAO.findAll();
	}

	Object onActivate(Long id) {
		course = courseDAO.findByID(id);
		courses = courseDAO.findAll();

		if (course == null) {
			errorPage.setMessage("Error while trying to view course! ");
			return errorPage;
		}

		return null;

	}

}
